//package cn.book.bus.utils;
//
//import com.actionsoft.bpms.bo.engine.BO;
//import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance;
//import com.actionsoft.bpms.commons.database.RowMap;
//import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
//import com.actionsoft.bpms.util.DBSql;
//import com.actionsoft.sdk.local.SDK;
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//
//import java.util.List;
//import java.util.concurrent.*;
//
//public class QueueUtil {
//    private static volatile QueueUtil queueUtil ;
//
//    private static ConcurrentLinkedQueue<String> queue;
//    private static boolean flag = true;         //是否处理队列
//    private static boolean flag1 = true;        //是否允许提交
//
//    public boolean getFlag1(){
//        return flag1;
//    }
//
//    private QueueUtil() {
//    }
//    public ResponseObject changeFlag(){
//        if (queue.size() != 0 && flag){
//            return ResponseObject.newErrResponse("关闭失败！！队列剩余任务数："+queue.size());
//        }
//        flag = !flag;
//        if (flag){
//            handleData();
//        }
//        ResponseObject responseObject = ResponseObject.newOkResponse("修改成功");
//        String msg = !flag ? "已关闭队列处理" : "已开启队列处理";
//        responseObject.put("result",msg);
//        return responseObject;
//    }
//
//    public ResponseObject getQueueNumber(){
//        ResponseObject responseObject = ResponseObject.newOkResponse("查询成功");
//        responseObject.put("number",queue.size());
//        return responseObject;
//    }
//
//    public boolean changeFlag1(){
//        flag1 = !flag1;
//        return flag1;
//    }
//
//    static Thread s_thread = null;
//    public synchronized static void handleData(){
//        if (s_thread == null) {
//            s_thread = new Thread(() -> {
//                while (flag) {
//                    String poll = queue.poll();
//                    if (poll == null) {
//                        try {
//                            Thread.sleep(5);
//                        } catch (InterruptedException e) {
//                            s_thread = null;
//                            throw new RuntimeException(e);
//                        }
//                    }
//                    else {
//                        String code = JSON.parseObject(poll).getString("code");
//                        RowMap byKeyField = DBSql.getMap("select STUDENT_ID,TASK_STATUS from BO_EU_STUDENT_EAV_RESULT where RESULT_ID = ?", code);
//                        if (null == byKeyField) {
//                            continue;
//                        }
//                        String task_status = byKeyField.getString("TASK_STATUS");
//                        if ("已评教".equals(task_status)) {
//                            continue;
//                        }
//                        JSONObject result = (JSONObject) JSON.parseObject(poll).get("result");
//                        //修改学生测评结果表
//                        if (result == null) {
//                            result = (JSONObject) JSON.parseObject(poll).get("data");
//                        }
//
//                        Float scoreAll = result.getFloat("scoreAll");
//                        String eva_content = result.getString("suggest");
//                        DBSql.update("update BO_EU_STUDENT_EAV_RESULT set SCORE=?,EVA_CONTENT=?,TASK_STATUS=? where RESULT_ID = ?", new Object[]{scoreAll, eva_content, "已评教", code});
//
//                        JSONArray indicators = result.getJSONArray("indicators");
//                        for (Object indicator : indicators) {
//                            JSONObject indicator_json = JSONObject.parseObject(String.valueOf(indicator));
//                            BO bo = new BO();
//                            bo.set("RESULT_ID", code); //测评结果序号
//                            bo.set("TARGET_SUBJECT_ID", indicator_json.getString("id")); //指标id
//                            bo.set("TARGET_SUBJECT_NAME", indicator_json.getString("name"));//指标名称
//                            bo.set("TARGET_TYPE", "一级指标");//指标类型
//                            bo.set("TARGET_SCORE_WEIGHT", indicator_json.getString("weight"));//权重
//                            scoreAll = indicator_json.getFloat("scoreAll");
//                            bo.set("SCORE", scoreAll);//等分
//                            ProcessInstance processInstance = SDK.getProcessAPI().createBOProcessInstance("obj_d6af4dfc78504739a74c09e63be69c70", "admin", "学生测评结果明细");
//                            SDK.getBOAPI().create("BO_EU_EVA_RESULT_DETAIL1", bo, processInstance.getId(), "admin");
//                            try {
//                                Thread.sleep(5);
//                            } catch (InterruptedException e) {
//                                throw new RuntimeException(e);
//                            }
//
//                            //记录二级指标
//                            JSONArray indicators1 = indicator_json.getJSONArray("indicator");
//                            for (Object indicator1 : indicators1) {
//                                JSONObject indicator_json1 = JSONObject.parseObject(String.valueOf(indicator1));
//                                BO bo1 = new BO();
//                                bo1.set("RESULT_ID", code); //测评结果序号
//                                bo1.set("TARGET_SUBJECT_ID", indicator_json1.getString("id")); //指标id
//                                bo1.set("TARGET_SUBJECT_NAME", indicator_json1.getString("name"));//指标名称
//                                bo1.set("TARGET_TYPE", "二级指标");//指标类型
//                                bo1.set("TARGET_CONTENT", indicator_json1.getString("basis"));//测评依据
//                                bo1.set("TARGET_SCORE_WEIGHT", indicator_json1.getString("weight"));//权重
//                                scoreAll = indicator_json1.getFloat("default_score");
//                                bo1.set("SCORE", scoreAll);//等分
//                                String grade = indicator_json1.getString("answer");
//                                bo1.set("GRADE", grade.replaceAll("[\\ud800\\udc00-\\udbff\\udfff\\ud800-\\udfff]", ""));//结果等级
//                                ProcessInstance processInstance1 = SDK.getProcessAPI().createBOProcessInstance("obj_d6af4dfc78504739a74c09e63be69c70", "admin", "学生测评结果明细2");
//                                SDK.getBOAPI().create("BO_EU_EVA_RESULT_DETAIL1", bo1, processInstance1.getId(), "admin");
//                                try {
//                                    Thread.sleep(5);
//                                } catch (InterruptedException e) {
//                                    throw new RuntimeException(e);
//                                }
//                            }
//                        }
//                    }
//                }
//                s_thread = null;
//            });
//            s_thread.start();
//        }else {
//            return;
//        }
//    }
//
//    public static QueueUtil getQueueUtil() {
//        if (queueUtil == null) {
//            synchronized (QueueUtil.class) {
//                if (queueUtil == null) {
//                    queueUtil = new QueueUtil();
//                    queue = new ConcurrentLinkedQueue<>();
//                    handleData();
//                }
//            }
//        }
//        return queueUtil;
//    }
//
//    public ConcurrentLinkedQueue<String> getQueue(){
//        return queue;
//    }
//
//}
